package com.higgins.eventtracking.client.health;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.higgins.eventtracking.client.FinanceTrackingService;
import com.higgins.eventtracking.client.FinanceTrackingServiceAsync;
import com.higgins.eventtracking.client.health.components.GenericChartPanel;
import com.higgins.eventtracking.client.health.components.GenericTabInterface;
import com.higgins.eventtracking.client.health.components.HealthOverviewChart;
import com.higgins.eventtracking.client.health.components.HealthOverviewChartListBox;
import com.higgins.eventtracking.client.health.fundamentals.AchievementTab;
import com.higgins.eventtracking.client.health.fundamentals.DigestionTab;
import com.higgins.eventtracking.client.health.fundamentals.FrameOfMindTab;
import com.higgins.eventtracking.client.health.fundamentals.GoalsTab;
import com.higgins.eventtracking.client.health.fundamentals.HolidaysTab;
import com.higgins.eventtracking.client.health.fundamentals.HourlyTab;
import com.higgins.eventtracking.client.health.fundamentals.HygieneTab;
import com.higgins.eventtracking.client.health.fundamentals.NegativeTab;
import com.higgins.eventtracking.client.health.fundamentals.RulesTab;
import com.higgins.eventtracking.client.health.fundamentals.SupportTab;
import com.higgins.eventtracking.client.health.fundamentals.TimetableTab;
import com.higgins.eventtracking.client.health.fundamentals.WellBeingTab;

public class RecordTab extends VerticalPanel	implements GenericTabInterface		{
	private final FinanceTrackingServiceAsync financeTrackingService = GWT
											.create(FinanceTrackingService.class);
	private TabPanel tabPanel = new TabPanel();
	private RulesTab rulesTab = new RulesTab(this, "FrameOfMindType");
	private RulesTab experienceTab = new RulesTab(this, "ExperienceType");
	private RulesTab evidenceTab = new RulesTab(this, "EvidenceType");
	private RulesTab mealsTab = new RulesTab(this, "MealType");
	private HolidaysTab holidaysTab = new HolidaysTab();
	private boolean firstRun = true;
	private boolean goals = false;
	private Integer tabIndex = null;
	private String tabTitle = null;
	
	@Override
	public Integer getTabIndex() {
		return tabIndex;
	}
	@Override
	public void setTabIndex(Integer index) {
		this.tabIndex = index;
	}
	@Override
	public String getTabTitle()	{
		return tabTitle;
	}
	@Override
	public void setTabTitle(String tabTitle)	{
		this.tabTitle = tabTitle;
	}

	public RecordTab()	{	
		
	}
	
	public void addGoalsTab()	{
		addTabs();
	}
	public void update()	{
		if (firstRun)	
			initialise();
	}
	public void initialise()	{
		populateTabPanel();
		firstRun = false;
	}
	public void populateTabPanel()	{
		addTabs();
		add(tabPanel);
	}
	private void addTabs()	{
		tabPanel.add(rulesTab, "Rules");
		rulesTab.update();
		tabPanel.add(experienceTab, "Experience");
		tabPanel.add(evidenceTab, "Evidence");
		tabPanel.add(mealsTab, "Meals");
		tabPanel.add(holidaysTab, "Holidays");
		tabPanel.selectTab(0);
		tabPanel.addSelectionHandler(createSelectionHandler());		
	}
	public SelectionHandler<Integer> createSelectionHandler()	{
		SelectionHandler<Integer> selectionHandler = new SelectionHandler<Integer>() {
	        @Override
	        public void onSelection(SelectionEvent<Integer> integerSelectionEvent) {
	            if (integerSelectionEvent.getSelectedItem() == 0)	{
	            	rulesTab.update();
	            }
	            if (integerSelectionEvent.getSelectedItem() == 1)	{
	            	experienceTab.update();
	            }
	            if (integerSelectionEvent.getSelectedItem() == 2)	{
	            	evidenceTab.update();
	            }
	            if (integerSelectionEvent.getSelectedItem() == 3)	{
	            	mealsTab.update();
	            }
	            if (integerSelectionEvent.getSelectedItem() == 4)	{
	            	holidaysTab.update();
	            }
	        }
		};
		return selectionHandler;
	}
	@Override
	public void addChartPanel(GenericChartPanel chartPanel) {
		// TODO Auto-generated method stub
		
	}

}
